-- MsgReminderM
-- Create by zouyb Oct/24/2015
-- 消息提醒管理

module("MsgReminderM", package.seeall);

-- 怪物信息
MSG_REMINDER_TYPE_MONSTER       = 1;
-- 成就
MSG_REMINDER_TYPE_ACHIEVEMENT   = 2;
-- 迷宫事件
MSG_REMINDER_TYPE_EVENT         = 3;
-- 迷宫中任务
MSG_REMINDER_TYPE_TASK          = 4;
-- 限时礼包
MSG_REMINDER_LIMIT_GIFT         = 5;
-- 迷宫暂离
MSG_REMINDER_TYPE_PAUSE         = 6;
-- 邮件提示
MSG_REMINDER_TYPE_MAIL          = 7;

-- 游戏内提醒(迷宫外)
local gameReminders = {};

local whenLeaveDungeon;

-- 模块初始化
function init()
    gameReminders = {};
    EventMgr.removeAll("MsgReminderM");
    EventMgr.register("MsgReminderM", event.LEAVE_DUNGEON, whenLeaveDungeon);
end

-- 添加游戏内提醒
function addReminder(reminderType, args)
    if gameReminders[reminderType] == nil then
        gameReminders[reminderType] = {};
    end

    local id = args["id"];
    gameReminders[reminderType][id] = args;
    notify(reminderType);
end

-- 删除游戏内提醒(表示已查看)
function removeReminder(reminderType, id)
    if gameReminders[reminderType] == nil then
        return;
    end

    gameReminders[reminderType][id] = nil;
    -- notify();
end

-- 通知有新消息提醒
function notify(type)
    EventMgr.fire(event.NEW_REMINDER_COMING, type);
end

-- 获取消息提醒列表
function getReminderList()
    return gameReminders;
end

-- 是否有消息需要提醒
function hasReminder()
    local reminderList = getReminderList();

    -- 统计提醒个数
    local totalCount = 0;
    for _, list in pairs(reminderList) do
        local count = 0;
        for _, _ in pairs(list) do
            count = count + 1;
        end

        totalCount = totalCount + count;
    end

    print("totalCount:"..totalCount);
    return totalCount > 0;
end

-- 获取某类消息个数
function getCountByType(type)
    local list = getReminderList()[type];

    if list == nil then
        return 0;
    end

    local count = 0;
    for _, _ in pairs(list) do
        count = count + 1;
    end

    return count;
end

whenLeaveDungeon = function()
    -- 离开迷宫时，清空迷宫内提醒
    gameReminders[MSG_REMINDER_TYPE_MONSTER] = {};
    gameReminders[MSG_REMINDER_TYPE_EVENT] = {};
    gameReminders[MSG_REMINDER_TYPE_TASK] = {};
    gameReminders[MSG_REMINDER_TYPE_MAIL] ={};
end

